Helmholtz energy conversion of cubics

As in Michelsen's book, PR and SRK can be given the common form: $$ p = \frac{RT}{v-b}-\frac{a(T)}{(v+\Delta_1b)(v+\Delta_2b)} $$ which can be ultimately converted to $$ \alpha^r = - \log{\left (- b \delta \rho_{r} + 1 \right )} - \frac{\tau a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )} $$


In [7]:
from __future__ import division
from sympy import *
from IPython.display import display, Math, Latex
from IPython.core.display import display_html
init_session(quiet=True, use_latex='mathjax')
init_printing()


IPython console for SymPy 0.7.6 (Python 2.7.10-64-bit) (ground types: python)

In [8]:
b,rho_r,tau,delta,T_c,R,Delta_1,Delta_2 = symbols('b,rho_r,tau,delta,T_c,R,Delta_1,Delta_2')
a = symbols('a', cls=Function)(tau)

In [13]:
alphar = -log(1-b*rho_r*delta)-a*tau/(R*b*T_c*(Delta_1-Delta_2))*log((1+Delta_1*b*rho_r*delta)/(1+Delta_2*b*rho_r*delta))
display(alphar)


$$- \log{\left (- b \delta \rho_{r} + 1 \right )} - \frac{\tau a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )}$$

In [4]:
def format_deriv(arg, itau, idel, RHS):
    """ 
    A function for giving a nice latex representation of 
    the partial derivative in question 
    """
    if itau+idel == 1:
        numexp = ''
    else:
        numexp = '^{{{s:d}}}'.format(s=itau+idel)
        
    if itau == 0:
        tau = ''
    elif itau == 1:
        tau = '\\partial \\tau'
    else:
        tau = '\\partial \\tau^{{{s:d}}}'.format(s=itau)
        
    if idel == 0:
        delta = ''
    elif idel == 1:
        delta = '\\partial \\delta'
    else:
        delta = '\\partial \\delta^{{{s:d}}}'.format(s=idel)
        
    temp = '\\frac{{\\partial{{{numexp:s}}} {arg:s}}}{{{{{tau:s}}}{{{delta:s}}}}} = '
    return Math(temp.format(**locals()) + latex(RHS))

In [5]:
for deriv_count in range(1,5):
    for dtau in range(deriv_count+1):
        ddelta = deriv_count-dtau
        #print dtau, ddelta
        display(format_deriv('\\alpha^r', dtau, ddelta, diff(diff(alphar,tau,dtau),delta,ddelta)))


$$\frac{\partial{} \alpha^r}{{}{\partial \delta}} = \frac{b \rho_{r}}{- b \delta \rho_{r} + 1} - \frac{\tau a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\frac{\Delta_{1} b \rho_{r}}{\Delta_{2} b \delta \rho_{r} + 1} - \frac{\Delta_{2} b \rho_{r} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}}\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)$$
$$\frac{\partial{} \alpha^r}{{\partial \tau}{}} = - \frac{\tau \frac{d}{d \tau} a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )} - \frac{a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )}$$
$$\frac{\partial{^{2}} \alpha^r}{{}{\partial \delta^{2}}} = b \rho_{r}^{2} \left(\frac{\Delta_{1} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)^{2}} + \frac{\Delta_{2} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)} + \frac{b}{\left(b \delta \rho_{r} - 1\right)^{2}}\right)$$
$$\frac{\partial{^{2}} \alpha^r}{{\partial \tau}{\partial \delta}} = - \frac{\tau \frac{d}{d \tau} a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\frac{\Delta_{1} b \rho_{r}}{\Delta_{2} b \delta \rho_{r} + 1} - \frac{\Delta_{2} b \rho_{r} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}}\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right) - \frac{a{\left (\tau \right )}}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\frac{\Delta_{1} b \rho_{r}}{\Delta_{2} b \delta \rho_{r} + 1} - \frac{\Delta_{2} b \rho_{r} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}}\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)$$
$$\frac{\partial{^{2}} \alpha^r}{{\partial \tau^{2}}{}} = - \frac{1}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \left(\tau \frac{d^{2}}{d \tau^{2}} a{\left (\tau \right )} + 2 \frac{d}{d \tau} a{\left (\tau \right )}\right) \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )}$$
$$\frac{\partial{^{3}} \alpha^r}{{}{\partial \delta^{3}}} = 2 b^{2} \rho_{r}^{3} \left(- \frac{\Delta_{1}^{2} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)^{3}} - \frac{\Delta_{1} \Delta_{2} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)^{2} \left(\Delta_{2} b \delta \rho_{r} + 1\right)} - \frac{\Delta_{2}^{2} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}} - \frac{b}{\left(b \delta \rho_{r} - 1\right)^{3}}\right)$$
$$\frac{\partial{^{3}} \alpha^r}{{\partial \tau}{\partial \delta^{2}}} = \frac{b \rho_{r}^{2}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) \left(\frac{\Delta_{1} \tau \frac{d}{d \tau} a{\left (\tau \right )}}{\Delta_{1} b \delta \rho_{r} + 1} + \frac{\Delta_{1} a{\left (\tau \right )}}{\Delta_{1} b \delta \rho_{r} + 1} + \frac{\Delta_{2} \tau \frac{d}{d \tau} a{\left (\tau \right )}}{\Delta_{2} b \delta \rho_{r} + 1} + \frac{\Delta_{2} a{\left (\tau \right )}}{\Delta_{2} b \delta \rho_{r} + 1}\right)$$
$$\frac{\partial{^{3}} \alpha^r}{{\partial \tau^{2}}{\partial \delta}} = - \frac{1}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\tau \frac{d^{2}}{d \tau^{2}} a{\left (\tau \right )} + 2 \frac{d}{d \tau} a{\left (\tau \right )}\right) \left(\frac{\Delta_{1} b \rho_{r}}{\Delta_{2} b \delta \rho_{r} + 1} - \frac{\Delta_{2} b \rho_{r} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}}\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)$$
$$\frac{\partial{^{3}} \alpha^r}{{\partial \tau^{3}}{}} = - \frac{1}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \left(\tau \frac{d^{3}}{d \tau^{3}} a{\left (\tau \right )} + 3 \frac{d^{2}}{d \tau^{2}} a{\left (\tau \right )}\right) \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )}$$
$$\frac{\partial{^{4}} \alpha^r}{{}{\partial \delta^{4}}} = 6 b^{3} \rho_{r}^{4} \left(\frac{\Delta_{1}^{3} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)^{4}} + \frac{\Delta_{1}^{2} \Delta_{2} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)^{3} \left(\Delta_{2} b \delta \rho_{r} + 1\right)} + \frac{\Delta_{1} \Delta_{2}^{2} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)^{2} \left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}} + \frac{\Delta_{2}^{3} \tau \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) a{\left (\tau \right )}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)^{3}} + \frac{b}{\left(b \delta \rho_{r} - 1\right)^{4}}\right)$$
$$\frac{\partial{^{4}} \alpha^r}{{\partial \tau}{\partial \delta^{3}}} = \frac{2 b^{2} \rho_{r}^{3}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) \left(- \frac{\Delta_{1}^{2} \tau \frac{d}{d \tau} a{\left (\tau \right )}}{\left(\Delta_{1} b \delta \rho_{r} + 1\right)^{2}} - \frac{\Delta_{1}^{2} a{\left (\tau \right )}}{\left(\Delta_{1} b \delta \rho_{r} + 1\right)^{2}} - \frac{\Delta_{1} \Delta_{2} \tau \frac{d}{d \tau} a{\left (\tau \right )}}{\left(\Delta_{1} b \delta \rho_{r} + 1\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)} - \frac{\Delta_{1} \Delta_{2} a{\left (\tau \right )}}{\left(\Delta_{1} b \delta \rho_{r} + 1\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)} - \frac{\Delta_{2}^{2} \tau \frac{d}{d \tau} a{\left (\tau \right )}}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}} - \frac{\Delta_{2}^{2} a{\left (\tau \right )}}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}}\right)$$
$$\frac{\partial{^{4}} \alpha^r}{{\partial \tau^{2}}{\partial \delta^{2}}} = \frac{b \rho_{r}^{2}}{R T_{c} \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\Delta_{1} - \frac{\Delta_{2} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\Delta_{2} b \delta \rho_{r} + 1}\right) \left(\frac{\Delta_{1}}{\Delta_{1} b \delta \rho_{r} + 1} + \frac{\Delta_{2}}{\Delta_{2} b \delta \rho_{r} + 1}\right) \left(\tau \frac{d^{2}}{d \tau^{2}} a{\left (\tau \right )} + 2 \frac{d}{d \tau} a{\left (\tau \right )}\right)$$
$$\frac{\partial{^{4}} \alpha^r}{{\partial \tau^{3}}{\partial \delta}} = - \frac{1}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right) \left(\Delta_{1} b \delta \rho_{r} + 1\right)} \left(\tau \frac{d^{3}}{d \tau^{3}} a{\left (\tau \right )} + 3 \frac{d^{2}}{d \tau^{2}} a{\left (\tau \right )}\right) \left(\frac{\Delta_{1} b \rho_{r}}{\Delta_{2} b \delta \rho_{r} + 1} - \frac{\Delta_{2} b \rho_{r} \left(\Delta_{1} b \delta \rho_{r} + 1\right)}{\left(\Delta_{2} b \delta \rho_{r} + 1\right)^{2}}\right) \left(\Delta_{2} b \delta \rho_{r} + 1\right)$$
$$\frac{\partial{^{4}} \alpha^r}{{\partial \tau^{4}}{}} = - \frac{1}{R T_{c} b \left(\Delta_{1} - \Delta_{2}\right)} \left(\tau \frac{d^{4}}{d \tau^{4}} a{\left (\tau \right )} + 4 \frac{d^{3}}{d \tau^{3}} a{\left (\tau \right )}\right) \log{\left (\frac{\Delta_{1} b \delta \rho_{r} + 1}{\Delta_{2} b \delta \rho_{r} + 1} \right )}$$

In [ ]: